OPC Studio User's Guide and Reference
Reading just the value (OPC UA)
View with Navigation Tools
Concepts > QuickOPC Concepts > QuickOPC Development Models > Imperative Programming Model > Imperative Programming Model for OPC Data (Classic and UA) > Obtaining Information (OPC Data) > Reading Attributes of OPC UA Nodes > Reading just the value (OPC UA)
In This Topic

Some applications need the actual data value for further processing (e.g. for computations that need be performed on the values), i.e. the status code must be Good and a valid value must be provided by the server, otherwise it is considered an error.

A single node and attribute

For such usage, call the ReadValue method, passing it the same arguments as to the Read method. The method will read the attribute data, check if the status is Good, and you will receive back an Object holding the actual data value. If the status code is not Good, the method will throw a UAStatusCodeException.

One-time read:

.NET

// This example shows how to read value of a single node, and display it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void Overload1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            var client = new EasyUAClient();

            Console.WriteLine("Obtaining value of a node...");
            object value;
            try
            {
                value = client.ReadValue(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853");
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"value: {value}");
        }
    }
}

COM

// This example shows how to read value of a single node, and display it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "ReadValue.h"

namespace _EasyUAClient
{
    void ReadValue::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Perform the operation
            _variant_t value = ClientPtr->ReadValue(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10853");
    
            // Display results
            _variant_t vString;
            vString.ChangeType(VT_BSTR, &value);
            _tprintf(_T("value: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}

Python

# This example shows how to read value of a single node, and display it.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

# Perform the operation.
try:
    value = IEasyUAClientExtension.ReadValue(client,
                                             endpointDescriptor,
                                             UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'))
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
print('value: ', value, sep='')

print('Finished.')

Repeated read:

.NET

// This example shows how to repeatedly read value of a single node, and display it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using System.Threading;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void Repeated()
        {
            const string endpointDescriptorUrlString =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"
            const string nodeIdExpandedText = "nsu=http://test.org/UA/Data/ ;i=10221";
            // Example settings with Softing dataFEED OPC Suite:
            //  endpointDescriptorUrlString = "opc.tcp://localhost:4980/Softing_dataFEED_OPC_Suite_Configuration1";
            //  nodeIdExpandedText = "nsu=Local%20Items ;s=Local Items.EAK_Test1.EAK_Testwert1_I4";

            // Instantiate the client object.
            var client = new EasyUAClient();

            for (int i = 1; i <= 60; i++)
            {
                Console.Write($"@{DateTime.Now}: ");

                // Obtain value of a node
                object value;
                try
                {
                    value = client.ReadValue(endpointDescriptorUrlString, nodeIdExpandedText);
                }
                catch (UAException uaException)
                {
                    Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                    return;
                }

                // Display results
                Console.WriteLine($"Read {value}");

                //
                Thread.Sleep(1000);
            }
        }
    }
}

COM

// This example shows how to repeatedly read value of a single node, and display it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure ReadValue.Repeated;
const
  EndpointDescriptorUrlString = 
    //'http://opcua.demo-this.com:51211/UA/SampleServer';
    //'https://opcua.demo-this.com:51212/UA/SampleServer/';
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
  NodeIdExpandedText = 'nsu=http://test.org/UA/Data/ ;i=10221';
// Example settings with Softing dataFEED OPC Suite:
//  EndpointDescriptorUrlString = 'opc.tcp://localhost:4980/Softing_dataFEED_OPC_Suite_Configuration1';
//  NodeIdExpandedText = 'nsu=Local%20Items ;s=Local Items.EAK_Test1.EAK_Testwert1_I4';
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  Value: OleVariant;
  I: Integer;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  for I := 1 to 60 do
  begin
    Write('@', TimeToStr(Now), ': ');

    // Obtain value of a node
    try
      Value := Client.ReadValue(EndpointDescriptorUrlString, NodeIdExpandedText);
    except
      on E: EOleException do
        WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
    end;

    // Display results
    WriteLn('Read ', Value);

    //
    Sleep(1000);
  end;
end;

 

// This example shows how to read a value of a specific attribute of a single node, and display it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void Overload2()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            UANodeDescriptor nodeDescriptor = "nsu=http://test.org/UA/Data/ ;i=10853";

            // Instantiate the client object
            var client = new EasyUAClient();

            // Obtain value of a DataType attribute
            object value;
            try
            {
                value = client.ReadValue(endpointDescriptor, nodeDescriptor, UAAttributeId.DataType);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"value type: {value?.GetType()}");
            Console.WriteLine($"value: {value}");
        }
    }
}

Python

# This example shows how to read a value of a specific attribute of a single node, and display it.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

nodeDescriptor = UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853')

# Instantiate the client object.
client = EasyUAClient()

# Obtain value of a DataType attribute.
try:
    value = IEasyUAClientExtension.ReadValue(client, endpointDescriptor, nodeDescriptor, UAAttributeId.DataType)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
print('value type: ', type(value), sep='')  # The output will differ from pure .NET languages such as C# or VB.NET.
print('value: ', value, sep='')

print()
print('Finished.')

 

Reading an array

.NET

// This example shows how to read a value from a single node that is an array of UInt16.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void ArrayOfUInt16()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object
            var client = new EasyUAClient();

            Console.WriteLine("Obtaining value of a node...");
            int[] value;
            try
            {
                // UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET).
                value = (int[])client.ReadValue(endpointDescriptor,
                    "nsu=http://test.org/UA/Data/ ;ns=2;i=10932");   // /Data.Dynamic.Array.UInt16Value
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            if (!(value is null))
            {
                Console.WriteLine(value[0]);
                Console.WriteLine(value[1]);
                Console.WriteLine(value[2]);
            }

            Console.WriteLine("Finished.");
        }
    }
}

Python

# This example shows how to read a value from a single node that is an array of UInt16.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


# Instantiate the client object.
client = EasyUAClient()

print('Obtaining value of a node...')
try:
    # UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET).
    value = IEasyUAClientExtension.ReadValue(client,
        UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
        UANodeDescriptor('nsu=http://test.org/UA/Data/ ;ns=2;i=10932')) # /Data.Dynamic.Array.UInt16Value
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
if value is not None:
    print(value[0])
    print(value[1])
    print(value[2])

print()
print('Finished.')

 

Multiple nodes or attributes

For reading just the data values of multiple data values (with Good status) in an efficient manner, call the ReadMultipleValues method (instead of multiple ReadValue calls in a loop). You pass in an array of UAReadArguments objects, and you will receive back an array of ValueResult objects.

.NET

// This example shows how to read the Value attributes of 3 different nodes at once. Using the same method, it is also possible 
// to read multiple attributes of the same node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadMultipleValues
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain values. By default, the Value attributes of the nodes will be read.
            ValueResult[] valueResultArray = client.ReadMultipleValues(new[]
                {
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845"),
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853"),
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855")
                });

            // Display results.
            foreach (ValueResult valueResult in valueResultArray)
            {
                if (valueResult.Succeeded)
                    Console.WriteLine($"Value: {valueResult.Value}");
                else
                    Console.WriteLine($"*** Failure: {valueResult.ErrorMessageBrief}");
            }


            // Example output:
            //
            //Value: 8
            //Value: -8.06803E+21
            //Value: Strawberry Pig Banana Snake Mango Purple Grape Monkey Purple? Blueberry Lemon^            
        }
    }
}

COM

// This example shows how to read the Value attributes of 3 different nodes at once. Using the same method, it is also possible 
// to read multiple attributes of the same node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include <atlsafe.h>
#include "ReadMultipleValues.h"

namespace _EasyUAClient
{
    void ReadMultipleValues::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            _UAReadArgumentsPtr ReadArguments1Ptr(_uuidof(UAReadArguments));
            ReadArguments1Ptr->EndpointDescriptor->UrlString = 
                //L"http://opcua.demo-this.com:51211/UA/SampleServer";
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            ReadArguments1Ptr->NodeDescriptor->NodeId->ExpandedText = L"nsu=http://test.org/UA/Data/ ;i=10845";

            _UAReadArgumentsPtr ReadArguments2Ptr(_uuidof(UAReadArguments));
            ReadArguments2Ptr->EndpointDescriptor->UrlString = 
                //L"http://opcua.demo-this.com:51211/UA/SampleServer";
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            ReadArguments2Ptr->NodeDescriptor->NodeId->ExpandedText = L"nsu=http://test.org/UA/Data/ ;i=10853";

            _UAReadArgumentsPtr ReadArguments3Ptr(_uuidof(UAReadArguments));
            ReadArguments3Ptr->EndpointDescriptor->UrlString = 
                //L"http://opcua.demo-this.com:51211/UA/SampleServer";
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            ReadArguments3Ptr->NodeDescriptor->NodeId->ExpandedText = L"nsu=http://test.org/UA/Data/ ;i=10855";

            CComSafeArray<VARIANT> arguments(3);
            arguments.SetAt(0, _variant_t((IDispatch*)ReadArguments1Ptr));
            arguments.SetAt(1, _variant_t((IDispatch*)ReadArguments2Ptr));
            arguments.SetAt(2, _variant_t((IDispatch*)ReadArguments3Ptr));
            CComVariant vArguments(arguments);

            // Obtain values. By default, the Value attributes of the nodes will be read.
            CComSafeArray<VARIANT> results;
            results.Attach(ClientPtr->ReadMultipleValues(&vArguments));
            
            // Display results
            for (int i = results.GetLowerBound(); i <= results.GetUpperBound(); i++)
            {
                _ValueResultPtr ValueResultPtr = results[i];

                _variant_t vString;
                vString.ChangeType(VT_BSTR, &ValueResultPtr->Value);
                _tprintf(_T("Value: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            }

            // Example output:
            //
            //Value: 8
            //Value: -8.06803E+21
            //Value: Strawberry Pig Banana Snake Mango Purple Grape Monkey Purple? Blueberry Lemon^            
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}

Python

# This example shows how to read the Value attributes of 3 different nodes at once. Using the same method, it is also possible
# to read multiple attributes of the same node.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

# Obtain values. By default, the Value attributes of the nodes will be read.
valueResultArray = IEasyUAClientExtension.ReadMultipleValues(client, [
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845')),
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853')),
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855')),
    ])

# Display results.
for valueResult in valueResultArray:
    if valueResult.Succeeded:
        print('Value: ', valueResult.Value, sep='')
    else:
        print('*** Failure: ', valueResult.ErrorMessageBrief, sep='')

print()
print('Finished.')

 

Reading DataType attributes 

.NET

// This example shows how to read the DataType attributes of 3 different nodes at once. Using the same method, it is also possible 
// to read multiple attributes of the same node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadMultipleValues
    {
        public static void DataType()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain values.
            ValueResult[] valueResultArray = client.ReadMultipleValues(new[]
                {
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", UAAttributeId.DataType),
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", UAAttributeId.DataType),
                    new UAReadArguments(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", UAAttributeId.DataType)
                });

            // Display results.
            foreach (ValueResult valueResult in valueResultArray)
            {
                Console.WriteLine();

                if (valueResult.Succeeded)
                {
                    Console.WriteLine($"Value: {valueResult.Value}");
                    var dataTypeId = valueResult.Value as UANodeId;
                    if (!(dataTypeId is null))
                    {
                        Console.WriteLine($"Value.ExpandedText: {dataTypeId.ExpandedText}");
                        Console.WriteLine($"Value.NamespaceUriString: {dataTypeId.NamespaceUriString}");
                        Console.WriteLine($"Value.NamespaceIndex: {dataTypeId.NamespaceIndex}");
                        Console.WriteLine($"Value.NumericIdentifier: {dataTypeId.NumericIdentifier}");
                    }
                }
                else
                    Console.WriteLine($"*** Failure: {valueResult.ErrorMessageBrief}");
            }

            // Example output:
            //
            //Value: SByte
            //Value.ExpandedText: nsu=http://opcfoundation.org/UA/ ;i=2
            //Value.NamespaceUriString: http://opcfoundation.org/UA/
            //Value.NamespaceIndex: 0
            //Value.NumericIdentifier: 2
            //
            //Value: Float
            //Value.ExpandedText: nsu=http://opcfoundation.org/UA/ ;i=10
            //Value.NamespaceUriString: http://opcfoundation.org/UA/
            //Value.NamespaceIndex: 0
            //Value.NumericIdentifier: 10
            //
            //Value: String
            //Value.ExpandedText: nsu=http://opcfoundation.org/UA/ ;i=12
            //Value.NamespaceUriString: http://opcfoundation.org/UA/
            //Value.NamespaceIndex: 0
            //Value.NumericIdentifier: 12
        }
    }
}

COM

// This example shows how to read the DataType attributes of 3 different nodes at
// once. Using the same method, it is also possible to read multiple attributes
// of the same node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure ReadMultipleValues.DataType;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  ReadArguments1, ReadArguments2, ReadArguments3: _UAReadArguments;
  Arguments, Results: OleVariant;
  I: Cardinal;
  Result: _ValueResult;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  ReadArguments1 := CoUAReadArguments.Create;
  ReadArguments1.EndpointDescriptor.UrlString := 
    //'http://opcua.demo-this.com:51211/UA/SampleServer';
    //'https://opcua.demo-this.com:51212/UA/SampleServer/';
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
  ReadArguments1.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10845';
  ReadArguments1.AttributeId := UAAttributeId_DataType;

  ReadArguments2 := CoUAReadArguments.Create;
  ReadArguments2.EndpointDescriptor.UrlString := 
    //'http://opcua.demo-this.com:51211/UA/SampleServer';
    //'https://opcua.demo-this.com:51212/UA/SampleServer/';
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
  ReadArguments2.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10853';
  ReadArguments2.AttributeId := UAAttributeId_DataType;

  ReadArguments3 := CoUAReadArguments.Create;
  ReadArguments3.EndpointDescriptor.UrlString := 
    //'http://opcua.demo-this.com:51211/UA/SampleServer';
    //'https://opcua.demo-this.com:51212/UA/SampleServer/';
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
  ReadArguments3.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10855';
  ReadArguments3.AttributeId := UAAttributeId_DataType;

  Arguments := VarArrayCreate([0, 2], varVariant);
  Arguments[0] := ReadArguments1;
  Arguments[1] := ReadArguments2;
  Arguments[2] := ReadArguments3;

  // Obtain values. By default, the Value attributes of the nodes will be read.
  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(Client.ReadMultipleValues(Arguments));

  // Display results
  for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
  begin
      Result := IInterface(Results[I]) as _ValueResult;
      WriteLn;
      if Result.Succeeded then
      begin
          WriteLn('Value: ', Result.Value);
          WriteLn('Value.ExpandedText: ', Result.Value.ExpandedText);
          WriteLn('Value.NamespaceUriString: ', Result.Value.NamespaceUriString);
          WriteLn('Value.NamespaceIndex: ', Result.Value.NamespaceIndex);
          WriteLn('Value.NumericIdentifier: ', Result.Value.NumericIdentifier);
      end
      else
        WriteLn('results(', I, ') *** Failure: ', Result.ErrorMessageBrief);
  end;
  
  VarClear(Results);
  VarClear(Arguments);

  // Example output:
  //
  //
  //Value: SByte
  //Value.ExpandedText: nsu=http://opcfoundation.org/UA/;i=2
  //Value.NamespaceUriString: http://opcfoundation.org/UA/
  //Value.NamespaceIndex: 0
  //Value.NumericIdentifier: 2
  //
  //Value: Float
  //Value.ExpandedText: nsu=http://opcfoundation.org/UA/;i=10
  //Value.NamespaceUriString: http://opcfoundation.org/UA/
  //Value.NamespaceIndex: 0
  //Value.NumericIdentifier: 10
  //
  //Value: String
  //Value.ExpandedText: nsu=http://opcfoundation.org/UA/;i=12
  //Value.NamespaceUriString: http://opcfoundation.org/UA/
  //Value.NamespaceIndex: 0
  //Value.NumericIdentifier: 12
end;

Python

# This example shows how to read the DataType attributes of 3 different nodes at once. Using the same method, it is also
# possible to read multiple attributes of the same node.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.AddressSpace import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

# Obtain values. By default, the Value attributes of the nodes will be read.
valueResultArray = IEasyUAClientExtension.ReadMultipleValues(client, [
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'),
                    UAAttributeId.DataType),
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'),
                    UAAttributeId.DataType),
    UAReadArguments(endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'),
                    UAAttributeId.DataType),
    ])

# Display results.
for valueResult in valueResultArray:
    print()
    #
    if valueResult.Succeeded:
        print('Value: ', valueResult.Value, sep='')
        if isinstance(valueResult.Value, UANodeId):
            dataTypeId = valueResult.Value
            print('dataTypeId.ExpandedText: ', dataTypeId.ExpandedText, sep='')
            print('dataTypeId.NamespaceUriString: ', dataTypeId.NamespaceUriString, sep='')
            print('dataTypeId.NamespaceIndex: ', dataTypeId.NamespaceIndex, sep='')
            print('dataTypeId.NumericIdentifier: ', dataTypeId.NumericIdentifier, sep='')
    else:
        print('*** Failure: ', valueResult.ErrorMessageBrief, sep='')

print()
print('Finished.')

Read Parameters

It is possible to specify read parameters, such as the maximum value age, or that the read should be performed from the cache, or directly from the device (data source). For more information, see Reading Attributes of OPC UA Nodes.

Advanced

If you access some node or nodes repeatedly, it might be possible to improve the performance of it by (pre-)registering the node or nodes with the server. The performance improvement will only occur if the target OPC UA server supports the necessary node registration services. For more information, see OPC UA Node Registration Service.

See Also

Knowledge Base

Installed Examples - Client Web

Examples - Client OPC Data Access

Examples - Client OPC Unified Architecture

Installed Examples - Client Windows Forms

Installed Examples - Client WPF